# 693 简单： 交替位二进制数

class Solution:
    def hasAlternatingBits(self, n: int) -> bool:
        # b = bin(n)
        # # print(b)
        # for i in range(3, len(b)):
        #     if b[i - 1] == b[i]:
        #         # print(b[i - 1], b[i])
        #         return False
        # return True

        a = n ^ (n >> 1)
        return a & (a + 1) == 0


s = Solution()
print(s.hasAlternatingBits(7))
